<!-- 质检管理 -->
<template>
	<a-card :bordered="false">
		<a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
			<a-row :gutter="24">
				<a-col :span="6">
					<a-form-item label="通话序列号" name="callId">
						<a-input v-model:value="searchFormState.callId" placeholder="请输入通话序列号" enter-button allowClear />
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="被叫" name="liaisonPhone">
						<a-input v-model:value="searchFormState.liaisonPhone" placeholder="请输入被叫" enter-button allowClear />
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="坐席姓名" name="userName">
						<a-input v-model:value="searchFormState.userName" placeholder="请输入坐席姓名" enter-button allowClear />
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="所属部门" name="deptId">
						<DeptSelect v-model:value="searchFormState.deptId" />
					</a-form-item>
				</a-col>
				<!-- <a-col :span="6">
					<a-form-item label="AI审核结果" name="aiApproveStatus">
						<a-select
							v-model:value="searchFormState.aiApproveStatus"
							placeholder="请选择AI审核结果"
							mode="multiple"
							:options="voiceCheckStatus"
							allowClear
						/>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="质检审核结果" name="qualityApproveStatus">
						<a-select
							v-model:value="searchFormState.qualityApproveStatus"
							:options="voiceCheckStatus"
							mode="multiple"
							:size="size"
							placeholder="请选择质检审核结果"
							allowClear
						></a-select>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="主管审核结果" name="supervisorApproveStatus">
						<a-select
							v-model:value="searchFormState.supervisorApproveStatus"
							mode="multiple"
							placeholder="请选择主管审核结果"
							:options="voiceCheckStatus"
							allowClear
						/>
					</a-form-item>
				</a-col> -->
				<a-col :span="6">
					<a-form-item label="AI审核" name="aiApproveStatus">
						<a-select
							v-model:value="searchFormState.aiApproveStatus"
							placeholder="请选择AI审核结果"
							mode="multiple"
							:options="voiceCheckStatus"
							allowClear
						/>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="分公司质检审核" name="qualityApproveStatus">
						<a-select
							v-model:value="searchFormState.qualityApproveStatus"
							:options="voiceCheckStatus"
							mode="multiple"
							:size="size"
							placeholder="请选择分公司质检审核结果"
							allowClear
						></a-select>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="总部质检审核" name="supervisorApproveStatus">
						<a-select
							v-model:value="searchFormState.supervisorApproveStatus"
							mode="multiple"
							placeholder="请选择总部质检审核结果"
							:options="voiceCheckStatus"
							allowClear
						/>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="终审" name="masterApproveStatus">
						<a-select
							v-model:value="searchFormState.masterApproveStatus"
							mode="multiple"
							placeholder="请选择终审结果"
							:options="voiceCheckStatus"
							allowClear
						/>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="回传时间">
						<a-range-picker
							v-model:value="createTimeArr"
							:default-value="[dayjs('2024-11-11', 'YYYY-MM-DD'), dayjs('2024-11-15', 'YYYY-MM-DD')]"
						/>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="命中关键词" name="keyword">
						<a-input
							v-model:value="searchFormState.keyword"
							placeholder="请输入命中关键词"
							enter-button
							allowClear
						/>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-button type="primary" @click="tableRef.refresh(true)">查询</a-button>
					<a-button class="ml-3" @click="reset">重置</a-button>
				</a-col>
			</a-row>
		</a-form>
	</a-card>
	<a-card :bordered="false" class="mt-2">
		<s-table ref="tableRef" :columns="columns" :data="loadData" bordered :row-key="(record) => record.id">
			<template #operator>
				<a-space>
					<a-button type="primary" @click="formRef.onOpen()">
						<template #icon>
							<plus-outlined />
						</template>
						新增
					</a-button>
					<a-button type="primary" @click="toExport" :loading="exprtLoading">导出</a-button>
				</a-space>
			</template>
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'action'">
					<a-space>
						<a @click="formRef.onOpen(record)">详情</a>
					</a-space>
				</template>
				<template v-if="column.dataIndex === 'aiApproveStatusName'">
					<a-space>
						{{
							record.keyword && record.aiApproveStatusName === '暂未进行审核'
								? '客户异常'
								: record.aiApproveStatusName
						}}
					</a-space>
				</template>
			</template>
		</s-table>
	</a-card>
	<Detail ref="formRef" @successful="tableRef.refresh(true)" />
</template>
<script setup name="checks">
	// import Detail from '@/views/qc/voice/check/detail2.vue'
	import Detail from '@/views/qc/voice/check/detail3.vue'
	import voiceCheckApi from '@/api/qc/voice/check/voiceCheckApi'
	import DeptSelect from '@/components/Tjzy/Dept/index.vue'
	import tool from '@/utils/tool'
	import dayjs from 'dayjs'
	import downloadUtil from '@/utils/downloadUtil'
	// ===========================================DATA======================================================

	const size = ref('middle')
	const searchFormRef = ref()
	const searchFormState = ref({
		current: 1,
		size: 10,
		callId: undefined,
		liaisonPhone: undefined,
		userName: undefined,
		deptId: undefined,
		keyword: undefined
	})
	const tableRef = ref()
	const formRef = ref()
	const voiceCheckStatus = tool.dictList('voiceCheckStatus')
	const columns = [
		{
			title: '呼叫序列号',
			dataIndex: 'callId'
		},
		{
			title: '命中关键词',
			dataIndex: 'keyword'
		},
		{
			title: '被叫',
			dataIndex: 'liaisonPhone'
		},
		{
			title: '坐席账号',
			dataIndex: 'agentName'
		},
		{
			title: '坐席姓名',
			dataIndex: 'userName'
		},
		{
			title: '所属公司',
			dataIndex: 'deptName'
		},
		// {
		// 	title: '通话时长',
		// 	dataIndex: 'callDuration'
		// },
		{
			title: '检查时间',
			dataIndex: 'createTime'
		},
		// {
		// 	title: 'AI审核结果',
		// 	dataIndex: 'aiApproveStatusName'
		// },
		// {
		// 	title: '质检审核结果',
		// 	dataIndex: 'qualityApproveStatusName'
		// },
		// {
		// 	title: '主管审核结果',
		// 	dataIndex: 'supervisorApproveStatusName'
		// },
		{
			title: 'AI审核',
			dataIndex: 'aiApproveStatusName'
		},
		{
			title: '分公司审核',
			dataIndex: 'qualityApproveStatusName'
		},
		{
			title: '总部审核',
			dataIndex: 'supervisorApproveStatusName'
		},
		{
			title: '终审',
			dataIndex: 'masterApproveStatusName'
		},
		{
			title: '操作',
			dataIndex: 'action',
			align: 'center',
			scopedSlots: { customRender: 'action' }
		}
	]
	const createTimeArr = ref([dayjs().startOf('day'), dayjs().endOf('day')])
	let exprtLoading = ref(false)
	// ===========================================METHODS==================================================
	const reset = () => {
		searchFormRef.value.resetFields()
	}
	// ===========================================REQUEST==================================================
	const loadData = (parameter) => {
		searchFormState.value.current = parameter.current
		searchFormState.value.size = parameter.size
		if (createTimeArr.value != null) {
			searchFormState.value.beginTime = createTimeArr.value[0].format('YYYY-MM-DD')
			searchFormState.value.endTime = createTimeArr.value[1].format('YYYY-MM-DD')
		} else {
			searchFormState.value.beginTime = undefined
			searchFormState.value.endTime = undefined
		}
		return voiceCheckApi.pageList(searchFormState.value).then((res) => {
			return res
		})
	}
	const toExport = () => {
		exprtLoading.value = true
		const data = JSON.parse(JSON.stringify(searchFormState.value))
		// delete data.current
		// delete data.size
		voiceCheckApi
			.export(data)
			.then((res) => {
				downloadUtil.resultDownload(res)
				exprtLoading.value = false
			})
			.catch(() => {
				exprtLoading.value = false
			})
	}
</script>
